<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>
<form name="form1" id="form1" action="<%-- ${systemctx}/sample/saveSample.web --%>" method="post">
	<div class="pageMain">
		<input type="hidden" name="ids" id="ids">
		<div class="pageTitle">
		<%=MessageResourcesUtils.getMessage(request, "systemmanage.storemanagement.title") %>
		<span></span>
		<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeuser.title") %>
		<span></span>
		<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeuser.userlist.title") %>
		</div>
		<div class="pageBody">
			<div class="form-group">
				<ul>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.number") %></label>
						<span>
							<input type="text" id="storecode" name="storecode" value="" />
							<input type="hidden" id="storeid" name="storeid"  >
						</span>
					</li>
					<li>
						<i></i>
						<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.name") %></label>
						<span><input type="text" id="storename" name="storename" value="" readonly="readonly" /></span>
					</li>
				</ul>
			</div>	
		</div>
		<div class="button-group">
			<input type="button" class="btn btn-default" id="butQuery" name="butQuery" value="<%=MessageResourcesUtils.getMessage(request, "common.button.query") %>" />
			<input type="button" class="btn btn-default" onclick="countryAdd()" value="<%=MessageResourcesUtils.getMessage(request, "common.button.add") %>" />
			<input type="button" class="btn btn-default" id="butUpdatePasw" name="butUpdatePasw" value="<%=MessageResourcesUtils.getMessage(request, "systemmanage.User.add.pwd") %>" />
		</div>
		<table>
			<tbody>
				<tr>
					<td>
						<table id="datagrid"></table>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</form>
<script type="text/javascript">
	function getIds() {
		var ids = "";
		var rows = $('#datagrid').datagrid('getChecked');
		if (rows.length == 0) {
			alert("<%=MessageResourcesUtils.getMessage(request, "dailyoperation.selects.warning")%>");
			return;
		} else {
			for (var i = 0; i < rows.length; i++) {
				var email = rows[i].email;
				if(email == ''){
					var str1 = '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeuser.alert1")%>';
					var str2 = '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeuser.alert2")%>';
					alert(str1 + rows[i].loginname + str2);
					break;
				}
				ids += rows[i].id + ":" + rows[i].email + ",";
			}
			if (ids != '') {
				ids = ids.substring(0,ids.length - 1);
			}
			return ids;
		}
	}
	$(document).ready(function() {
		$("#butUpdatePasw").click(function(){
			var ids = getIds();
			if (ids != '' && ids != undefined) {
				if(confirm('<%=MessageResourcesUtils.getMessage(request, "systemmanage.user.spassword.update.confoirm")%>')){
					showSending();
					$("#ids").val(ids);
					$.ajax({
						type : 'POST',
						url : '${systemctx}/systemmanage/user/sendMail.web',
						data : $("#form1").serialize(),
						dataType : 'json',
						success : function(data) {
							//关闭执行...
							closeSending();
							$.fn.ajaxmessage(data);
						}
					});
				}
			}
		});
		
		$("#storecode").issNewMagnifier({
			title: '<%=MessageResourcesUtils.getMessage(request, "systemmanage.databasebinding.storemagnifiertitle") %>',
			url: '${systemctx}/publicMagnifier/publicMagnifier.json',
			sortName : 'modifytime',
			sortOrder : 'desc',
			linkName: 'number',
			callSqlKey: 'queryStoreMagnifierSql',
			changeIgnore: ['storecode'],
			columns: [[
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.number") %>', field:'number', width:220, sortable:true, align: 'left', formel:'storecode'},
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.name") %>', field:'name', width:300, sortable:true, align: 'left', formel:'storename'},
			       	{field:'id', hidden:true, formel:'storeid'}
			]],
			onBeforeOpen:function(p){
		      var queryParams = {
		    		  querystore: '%' + $("#storecode").val() + '%',
		    		  statusid: <%=SysConstant.RecordStatus.VALID %>,
		    		  state : <%=SysConstant.CommonApproveStatus.OK %>
		      };
		      return queryParams;
		    }
		});
		 
			//加载分页控件 datagrid
			$('#datagrid').issdatagrid({
				formid : 'form1',
				title : '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeuser.userlist.title") %>',
				width : 'auto',
				nowrap : true,
				autoRowHeight : false,
				singleSelect : false,
				striped : true,
				//collapsible:true,
				url : '${systemctx}/dailyoperation/storeuser/queryAdminUserListInfoDataGrid.json',
				sortName : 'modifytime',
				sortOrder : 'desc',
				remoteSort : true,
				idField : 'id',
				pagination : true,
				rownumbers : true,
				showFooter : true,
				queryParams:$('#form1').serializeObject(),
				columns : [ [ 
				  	{field:'ck', checkbox:true},
				  	{
						field : 'id',
						title : '<%=MessageResourcesUtils.getMessage(request, "common.button.operation") %>',
						width : 60,
						align : 'center',
						formatter : operate
					},{
						title : '<%=MessageResourcesUtils.getMessage(request, "systemmanage.User.add.userloginname") %>',
						field : 'loginname',
						width : 350,
						sortable : true,
						align : 'left'
					},{
				  		title : '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.number") %>',
						field : 'number',
						width : 200,
						sortable : true,
						align : 'left'
					}, {
						title : '<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.name") %>',
						field : 'name',
						width : 220,
						sortable : true,
						align : 'left'
					}
				] ],
				onLoadSuccess : function(data) {

				}
			});

			$('#butQuery').click(function() {
				$('#datagrid').datagrid('load',$('#form1').serializeObject());
			});

			function operate(val, row) {
				return '<a href="javascript:void(0);" class="easyui-linkbutton" onclick="adminUserUpdate('
						+ val
						+ ')"><%=MessageResourcesUtils.getMessage(request, "common.button.update") %></a> ';
			}

		});
	function countryAdd() {
		$(this).isswindow({
			title : '商户用户信息-新增',
			noheader : true,
			url : '${systemctx}/dailyoperation/storeuser/toAddAdminUser.web'
		});
	}
	
	function adminUserUpdate(val) {
		var id = val;
		$(this).isswindow({
			title : '商户用户信息-修改',
			noheader : true,
			url : '${systemctx}/dailyoperation/storeuser/toUpdateAdminUser.web?id=' + id
		});
	}
	
	function adminUserDelete(val) {
		var id = val;
		if (confirm("确认删除?")) {
			//正在执行...
			showSending();
			$.ajax({
				type : 'GET',
				url : '${systemctx}/dailyoperation/storeuser/deleteAdminUser.json?id=' + id,
				dataType : 'json',
				success : function(data) {
					//关闭执行...
					closeSending();
					//显示AJAX请求后的提示信息
					$.fn.ajaxmessage(data);
					$('#datagrid').datagrid('reload',
							$('#form1').serializeObject());
					$('#datagrid').datagrid('clearSelections');
				}
			});
		}
	}
	
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>